import GlobalEvent from "../../../cfw/event/GlobalEvent";
import { EventName } from "../../../public/Config";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GameTipView extends cc.Component {

    @property([cc.Node])
    tips: cc.Node[] = [];


    start() {
        GlobalEvent.instance().on(EventName.CHANGE_GAME_TIP, this.changeGameTip, this)

        GlobalEvent.instance().on(EventName.CLOSE_GAME_TIP, this.closeGameTip, this)
        // GlobalEvent.instance().on(EventName.OPEN_GAME_TIP, this.openGameTip, this)
        this.closeGameTip()
    }

    onDestroy() {
        GlobalEvent.instance().off(EventName.CHANGE_GAME_TIP, this.changeGameTip, this)
        // GlobalEvent.instance().off(EventName.OPEN_GAME_TIP, this.openGameTip, this)
        GlobalEvent.instance().off(EventName.CLOSE_GAME_TIP, this.closeGameTip, this)
    }

    changeGameTip(tipID: number) {
        if (!this.node.active) {
            this.node.active = true;
        }
        let i = tipID - 1;
        // cc.log(' tipID ',tipID)
        for (let index = 0; index < this.tips.length; index++) {
            const element = this.tips[index];
            if (i == index) {
                element.active = true;
            } else {
                element.active = false;
            }
        }
    }

    openGameTip() {
        // this.node.active = true;
    }

    closeGameTip() {
        // this.node.active = false;
        if (this.node.active) {
            this.node.active = false;
        }        
    }



}
